package com.example.demo.controller;

import com.example.demo.Constants;
import com.example.demo.service.UserService;
import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 25228
 * Date: 2025-05-10
 * Time: 22:34
 */
@RestController
@RequestMapping("/User")
public class UserController {
    @Autowired
    private UserService userService;
    @RequestMapping("/login")
    public boolean login(String name, String password, HttpSession session){
        //校验不为空
        if (!StringUtils.hasLength(name)||!StringUtils.hasLength(password)){
            return false;
        }
        //校验是否正确
        /*if ("admin".equals(userName)&&"admin".equals(password)){
            return true;
        }

         */
        //校验是否正确
        Boolean result=userService.checkPassword(name,password);
        if (result){
            session.setAttribute(Constants.SESSION_LOGIN_USER_NAME,name);
        }
        return result;
    }
}
